

package com.maoshi.shop.dao;

import cn.hutool.core.date.DateTime;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.maoshi.shop.bean.app.dto.MyOrderDto;
import com.maoshi.shop.bean.app.dto.OrderCountData;
import com.maoshi.shop.bean.distribution.UserShoppingDataDto;
import com.maoshi.shop.bean.model.Order;
import com.maoshi.shop.bean.param.OrderParam;
import com.maoshi.shop.bean.param.OrderPayParam;
import com.maoshi.shop.common.util.PageAdapter;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

import java.util.Date;
import java.util.List;

public interface OrderMapper extends BaseMapper<Order> {

    Order getOrderByOrderNumber(@Param("orderNumber") String orderNumber);

    List<Order> listUnRefundOrderAndOrderItems(@Param("orderStatus") Integer orderStatus, @Param("lessThanUpdateTime") DateTime lessThanUpdateTime);

    void cancelOrders(@Param("orders") List<Order> orders);

    void receiptOrder(@Param("orders") List<Order> orders);

    void updateByToPaySuccess(@Param("orderNumbers") List<String> orderNumbers, @Param("payType") Integer payType);

    List<Order> listOrdersDetialByOrder(@Param("order") Order order, @Param("startTime") Date startTime, @Param("endTime") Date endTime);

    List<Order> listOrdersDetialByOrderParam(@Param("adapter") PageAdapter adapter, @Param("orderParam") OrderParam orderParam);

    Long countOrderDetial(@Param("orderParam") OrderParam orderParam);

    UserShoppingDataDto calculateUserInShopData(@Param("shopId") Long shopId, @Param("userId") String userId);

    List<MyOrderDto> listMyOrderByUserIdAndStatus(@Param("adapter") PageAdapter adapter, @Param("userId") String userId, @Param("status") Integer status, @Param("isComm") Integer isComm);

    Long countMyOrderByUserIdAndStatus(@Param("userId") String userId, @Param("status") Integer status, @Param("isComm") Integer isComm);

    void deleteOrders(@Param("orders") List<Order> orders);

    OrderCountData getOrderCount(String userId);


    OrderPayParam getOrderCountByShopId(@Param("shopId") Long shopId, @Param("startTime") Date startTime, @Param("endTime") Date endTime);

    List<OrderPayParam> getActualTotalByHour(@Param("shopId") Long shopId, @Param("startTime") Date startTime, @Param("endTime") Date endTime);

    List<OrderPayParam> getActualTotalByDay(@Param("shopId") Long shopId, @Param("startTime") Date startTime, @Param("endTime") Date endTime);

    List<OrderPayParam> getPayOrderByTime(@Param("shopId") Long shopId, @Param("startTime") Date startTime, @Param("endTime") Date endTime);


    void cancelSeckillOrderByTime(@Param("now") Date now);

    /**
     * 更新订单为待成团
     */
    int updateToWaitGroup(@Param("orderNumber") String orderNumber);

    /**
     * 通过拼团团队id更新订单为已发货状态
     */
    int updateToWaitDelivery(@Param("groupTeamId") Long groupTeamId);

    /**
     * 通过用户id和订单编号获取订单
     */
    Order getOrderByOrderNumberAndUserId(@Param("orderNumber") String orderNumber, @Param("userId") String userId);

    /**
     * 根据订单号获取订单及订单项
     *
     * @param orderNumber
     * @return
     */
    Order getOrderAndOrderItemByOrderNumber(@Param("orderNumber") String orderNumber);

    Integer hasBuySuccessProd(@Param("prodId") Long prodId, @Param("userId") String userId);

    /**
     * 模糊查询订单列表中的某一项订单
     */
    List<MyOrderDto> listMyOrderByParams(@Param("adapter") PageAdapter adapter, @Param("userId") String userId, @Param("status") Integer status, @Param("orderName") String orderName, @Param("orderTimeStatus") Integer orderTimeStatus, @Param("preTime") String preTime, @Param("orderType") Integer orderType);

    /**
     * 统计模糊查询订单列表中的某一项订单
     */
    Long countMyOrderByParams(@Param("userId") String userId, @Param("status") Integer status, @Param("orderName") String orderName, @Param("orderTimeStatus") Integer orderTimeStatus, @Param("preTime") String preTime,@Param("orderType") Integer orderType);

    List<Order> listOrdersDetialByOrderInfo(@Param("orderParam") OrderParam orderParam);

    List<Order> getOrderPayInfoByOrderNumber(@Param("orderNumberList") List<String> orderNumberList);
}
